@if(!is_null($hospital))
    <h3 class="text-center margin-bottom-20">{{ $hospital->name }}</h3>
@endif
{{--基本信息--}}
<div class="baseMessage">
    <p>
        <span class="title">&nbsp;姓&nbsp;&nbsp;&nbsp;名：</span>
        <span class="content">&nbsp;&nbsp;{{ $patient['name'] }}</span>
    </p>

    <p>
        <span class="title">病案号：</span>
        <span class="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ $patient['medical_number'] }}</span>
    </p>

    <p>
        <span class="title">就诊日期：</span>
        <span class="content">{{ $record['clinic_at'] }}</span>
    </p>

    <p>
        <span class="title">科室：</span>
        <span class="content">内分泌科</span>
    </p>

    <p>
        {{--<span class="title">年龄：</span>--}}
        <span class="content">{{ $patient->sex['value'] }}</span> /
        <span class="content">{{ $patient['age'] }} 岁</span>
    </p>

    {{--<p>--}}
    {{--<span class="title">性别：</span>--}}
    {{--<span class="content">{{ $patient->sex['value'] }}</span>--}}
    {{--</p>--}}

    {{--<p>--}}
    {{--<span class="title">糖尿病类型：</span>--}}
    {{--<span class="content">{{ isset($patient['diabetes_type']['value']) ? $patient['diabetes_type']['value'] : '' }}</span>--}}
    {{--</p>--}}
</div>
{{--主诉--}}
@if (isset($complaint) && !is_null($complaint))
    <div>
        @if(!isEmpty($complaint))
            <p class="caseTitle">主诉</p>
        @endif
        <div>
            @foreach($complaint['print'] as $item)
                <p>{{ $item }}</p>
            @endforeach
            @if(is_array($complaint['model']['medication']))
                用药：
                @foreach($complaint['model']['medication'] as $item)
                    <span>
                            {{ fr($item, 'start_time',"：") }}
                        {{ fr($item, 'name','，') }}
                        {{ fr($item,'dosage.type','，')}}
                        @if ('每次剂量' == fr($item,'dosage.type'))
                            {{ $item['dosage']['value'],'，'}}
                        @else
                            {{ fe($item, 'dosage.values.morning', '早', '，') }}
                            {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                            {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                            {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                        @endif
                        {{ fr($item, 'dosage.unit','，') }}
                        {{ fr($item, 'usage','，') }}
                        {{ fr($item, 'frequency',' ') }}
                        {{ fr($item, 'remark',' ') }}；
                        </span>
                    {{--<tr>--}}
                    {{--<td>{{ $item['start_time'] }}</td>--}}
                    {{--<td>{{ $item['end_time'] }}</td>--}}
                    {{--<td>{{ $item['name'] }}</td>--}}

                    {{--@if (isset($item['dosage']['type']) && $item['dosage']['type'] == '每次剂量')--}}
                    {{--<td>{{ $item['dosage']['value'] }}</td>--}}
                    {{--@else--}}
                    {{--<td>--}}
                    {{--@if (isset($item['dosage']['values']['morning']))--}}
                    {{--早上 {{ $item['dosage']['values']['morning'] }},--}}
                    {{--@endif--}}
                    {{--@if (isset($item['dosage']['values']['atnoon']))--}}
                    {{--中午 {{ $item['dosage']['values']['atnoon'] }},--}}
                    {{--@endif--}}
                    {{--@if (isset($item['dosage']['values']['evening']))--}}
                    {{--晚上 {{ $item['dosage']['values']['evening'] }},--}}
                    {{--@endif--}}
                    {{--@if (isset($item['dosage']['values']['before_sleep']))--}}
                    {{--睡前 {{ $item['dosage']['values']['before_sleep'] }}--}}
                    {{--@endif--}}
                    {{--</td>--}}
                    {{--@endif--}}
                    {{--@if(isset($item['dosage']['unit']))--}}
                    {{--<td>{{ $item['dosage']['unit'] }}</td>--}}
                    {{--@endif--}}
                    {{--<td>{{ $item['usage'] }}</td>--}}
                    {{--<td>{{ $item['frequency'] }}</td>--}}
                    {{--<td>{{ $item['remark'] }}</td>--}}
                    {{--</tr>--}}
                @endforeach

            @endif
            @if(isset($complaint['model']->remark)&&!is_null($complaint['model']->remark)&&''!=$complaint['model']->remark)
                <p>备注信息：{{ $complaint['model']->remark }}</p>
            @endif
        </div>
    </div>
@endif

{{--现病史组--}}
<div>
    @if ($record['visit_type']['key'])
        @if((isset($hpiSub) && !is_null($hpiSub)) || (isset($follow) && !is_null($follow)))
            <p class="caseTitle">现病史</p>
        @endif
        @if(isset($hpiSub) && !is_null($hpiSub))
            @foreach($hpiSub as $sub)
                <div>
                    @foreach($sub['print'] as $print)
                        <span>{{ $print }}</span>
                    @endforeach
                </div>

                @if ($sub['model']->medication)
                    @foreach((array)$sub['model']->medication as $item)
                        <p>
                            {{ fr($item, 'start_time',"：") }}
                            {{ fr($item, 'name','，') }}
                            {{ fr($item,'dosage.type','，')}}
                            @if ('每次剂量' == fr($item,'dosage.type'))
                                {{ $item['dosage']['value'],'，'}}
                            @else
                                {{ fe($item, 'dosage.values.morning', '早', '，') }}
                                {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                                {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                                {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                            @endif
                            {{ fr($item, 'dosage.unit','，') }}
                            {{ fr($item, 'usage','，') }}
                            {{ fr($item, 'frequency',' ') }}
                            {{ fr($item, 'remark',' ') }}
                        </p>
                    @endforeach
                @endif
                @if($sub['model']->cn_medication)
                    @foreach((array)$sub['model']->cn_medication as $item)
                        @if(!isset($item['type']) || $item['type'] == 1)
                            <p>
                                @foreach($item['drugs'] as $drug)
                                    {{ $drug['name'] }} {{ $drug['weight'] }}g
                                @endforeach
                                {{ fe($item, 'usage', '煎法：', '，') }}
                                {{ fe($item, 'dosage', '频次：', '，') }}
                                {{ fe($item, 'frequency', '', '，') }}
                                {{ fe($item, 'dose', '总数：', '付') }}
                            </p>
                        @elseif($item['type'] == 3)
                            <p>
                                {{ fe($item, 'name') }}
                                {{ fe($item, 'start_time', '开始于', '，') }}
                                {{ fe($item, 'end_time', '结束于', '，') }}
                                {{ fe($item, 'times_per_day', '每日', '次，') }}
                                {{ fe($item, 'quantity_per_times', '每次') }}
                                {{ fe($item, 'quantity_unit', '', '，') }}
                                {{ fe($item, 'total', '共', '盒，') }}
                            </p>
                        @endif
                    @endforeach
                @endif
            @endforeach
        @endif
        @if(isset($hpi) && !is_null($hpi))
            @if (isset($hpi) && !is_null($hpi))
                @foreach($hpi['print'] as $item)
                    <p>{{ $item }}</p>
                @endforeach
                @if(isset($hpi['model']->remark)&&!is_null($hpi['model']->remark)&&''!=$hpi['model']->remark)
                    <p>备注信息：{{ $hpi['model']->remark }}</p>
                @endif
            @endif
        @endif
    @else
        @if((isset($hpiSub) && !is_null($hpiSub)) || (isset($follow) && !is_null($follow)))
            <p class="caseTitle">随诊</p>
        @endif
        @if(isset($hpiSub) && !is_null($hpiSub))
            @foreach($hpiSub as $sub)
                <div>
                    @foreach($sub['print'] as $print)
                        <span>{{ $print }}</span>
                    @endforeach
                </div>

                @if ($sub['model']->medication)
                    @foreach((array)$sub['model']->medication as $item)
                        <p>
                            {{ fr($item, 'start_time',"：") }}
                            {{ fr($item, 'name','，') }}
                            {{ fr($item,'dosage.type','，')}}
                            @if ('每次剂量' == fr($item,'dosage.type'))
                                {{ $item['dosage']['value'],'，'}}
                            @else
                                {{ fe($item, 'dosage.values.morning', '早', '，') }}
                                {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                                {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                                {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                            @endif
                            {{ fr($item, 'dosage.unit','，') }}
                            {{ fr($item, 'usage','，') }}
                            {{ fr($item, 'frequency',' ') }}
                            {{ fr($item, 'remark',' ') }}
                        </p>
                    @endforeach
                @endif
                @if($sub['model']->cn_medication)
                    @foreach((array)$sub['model']->cn_medication as $item)
                        @if(!isset($item['type']) || $item['type'] == 1)
                            <p>
                                @foreach($item['drugs'] as $drug)
                                    {{ $drug['name'] }} {{ $drug['weight'] }}g
                                @endforeach
                                {{ fe($item, 'usage', '煎法：', '，') }}
                                {{ fe($item, 'dosage', '频次：', '，') }}
                                {{ fe($item, 'frequency', '', '，') }}
                                {{ fe($item, 'dose', '总数：', '付') }}
                            </p>
                        @elseif($item['type'] == 3)
                            <p>
                                {{ fe($item, 'name') }}
                                {{ fe($item, 'start_time', '开始于', '，') }}
                                {{ fe($item, 'end_time', '结束于', '，') }}
                                {{ fe($item, 'times_per_day', '每日', '次，') }}
                                {{ fe($item, 'quantity_per_times', '每次') }}
                                {{ fe($item, 'quantity_unit') }}
                                {{ fe($item, 'total', '共', '盒，') }}
                            </p>
                        @endif
                    @endforeach
                @endif
            @endforeach
        @endif
        @if(isset($follow) && !is_null($follow))
            @if (isset($follow) && !is_null($follow))
                @foreach($follow['print'] as $item)
                    <p>{{ $item }}</p>
                @endforeach
                @if(isset($follow['model']->remark)&&!is_null($follow['model']->remark)&&''!=$follow['model']->remark)
                    <p>备注信息：{{ $follow['model']->remark }}</p>
                @endif
            @endif
        @endif
    @endif
</div>

{{--既往史--}}
@if (isset($past) && !is_null($past))
    <div>
        @if(!isEmpty($past))
            <p class="caseTitle">既往史</p>
        @endif
        <div>
            @foreach($past['print'] as $item)
                <p>{!! $item !!}</p>
            @endforeach
        </div>
        @if ($past['model']->operation)
            {{--<table class="table-bordered text-center">--}}
            {{--<caption>手术史：</caption>--}}
            {{--<thead>--}}
            {{--<tr>--}}
            {{--<th>手术日期</th>--}}
            {{--<th>手术名称</th>--}}
            {{--</tr>--}}
            {{--</thead>--}}
            {{--<tbody>--}}
            @foreach((array)$past['model']->operation as $item)
                <p>
                    {{ fe($item, 'time','，') }}
                    {{ fe($item, 'name') }}
                </p>
                {{--<tr>--}}
                {{--<td>{{ fe($item, 'time') }}</td>--}}
                {{--<td>{{ fe($item, 'name') }}</td>--}}
                {{--</tr>--}}
            @endforeach
            {{--</tbody>--}}
            {{--</table>--}}
        @endif
        @if ($past['model']->medication)

            @foreach((array)$past['model']->medication as $item)
                <p>
                    {{ fr($item, 'start_time',"：") }}
                    {{ fr($item, 'name','，') }}
                    {{ fr($item,'dosage.type','，')}}
                    @if ('每次剂量' == fr($item,'dosage.type'))
                        {{ $item['dosage']['value'],'，'}}
                    @else
                        {{ fe($item, 'dosage.values.morning', '早', '，') }}
                        {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                        {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                        {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                    @endif
                    {{ fr($item, 'dosage.unit','，') }}
                    {{ fr($item, 'usage','，') }}
                    {{ fr($item, 'frequency',' ') }}
                    {{ fr($item, 'remark',' ') }}
                </p>
                {{--<tr>--}}
                {{--<td>{{ fe($item, 'start_time') }}</td>--}}
                {{--<td>{{ fe($item, 'end_time') }}</td>--}}
                {{--<td>{{ fe($item, 'name') }}</td>--}}
                {{--<td>--}}
                {{--{{ $item['dosage']['type'] }} :--}}
                {{--@if ('每次剂量' == $item['dosage']['type'])--}}
                {{--{{ $item['dosage']['value'] }}--}}
                {{--@else--}}
                {{--{{ fe($item, 'dosage.values.morning', '早') }},--}}
                {{--{{ fe($item, 'dosage.values.atnoon', '中') }},--}}
                {{--{{ fe($item, 'dosage.values.evening', '晚') }},--}}
                {{--{{ fe($item, 'dosage.values.before_sleep', '睡前') }}--}}
                {{--@endif--}}
                {{--</td>--}}
                {{--<td>{{ fe($item, 'dosage.unit') }}</td>--}}
                {{--<td>{{ fe($item, 'usage') }}</td>--}}
                {{--<td>{{ fe($item, 'frequency') }}</td>--}}
                {{--<td>{{ fe($item, 'remark') }}</td>--}}
                {{--</tr>--}}
            @endforeach

        @endif
        <p>
        @if(isset($past['model']->remark)&&!is_null($past['model']->remark)&&''!=$past['model']->remark)
            <p>备注信息：{{ $past['model']->remark }}</p>
            @endif
            </p>
    </div>
@endif

{{--个人史--}}
@if (isset($person) && !is_null($person))
    <div>
        @if(!isEmpty($person))
            <p class="caseTitle">个人史</p>
        @endif
        <div>
            @foreach($person['print'] as $item)
                <span>{{ $item }}</span><br>
            @endforeach
            @if(isset($person['model']->remark)&&!is_null($person['model']->remark)&&''!=$person['model']->remark)
                <span>备注信息：{{ $person['model']->remark }}</span>
            @endif
        </div>
    </div>
@endif

{{--月经婚育史--}}
@if (isset($marriage) && !is_null($marriage))
    <div>
        @if(!isEmpty($marriage))
            <p class="caseTitle">月经婚育史</p>
        @endif
        <div>
            @foreach($marriage['print'] as $item)
                <span>{{ $item }}</span><br>
            @endforeach
            @if(isset($marriage['model']->remark)&&!is_null($marriage['model']->remark)&&''!=$marriage['model']->remark)
                <span>备注信息：{{ $marriage['model']->remark }}</span>
            @endif
        </div>
    </div>
@endif

{{--家族史--}}
@if (isset($family) && !is_null($family)&&!isEmpty($family))
    <div>
        <p class="caseTitle">家族史</p>
        <div>
            @foreach($family['print'] as $key => $item)

                @if ($key == 'extend')
                    @foreach(explode('；', $item) as $i)
                        @if ($i !== '')
                            <span>{!! $i !!}</span>
                        @endif
                    @endforeach
                @else
                    <span>{{ $item }}</span><br>
                @endif
            @endforeach
            @if(isset($family['model']->remark)&&!is_null($family['model']->remark)&&''!=$family['model']->remark)
                <span>备注信息：{{ $family['model']->remark }}</span>
            @endif
        </div>
    </div>
@endif

{{--体格检查--}}
@if (isset($physical) && !is_null($physical))
    <div>
        @if(!isEmpty($physical))
            <p class="caseTitle">体格检查</p>
        @endif
        <div>
            @foreach($physical['print'] as $item)
                <span>{!! $item !!}</span><br>
            @endforeach
            @if(isset($physical['model']->remark)&&!is_null($physical['model']->remark)&&''!=$physical['model']->remark)
                <span>备注信息：{{ $physical['model']->remark }}</span>
            @endif
        </div>
    </div>
@endif

{{--辅助检查--}}
@if (isset($auxiliary) && !is_null($auxiliary))
    <div>
        @if(!isEmpty($auxiliary))
            <p class="caseTitle">辅助检查</p>
        @endif
        <div>
            @foreach($auxiliary['print'] as $key => $item)
                <p>检查日期 {{ $key }}</p>
                @foreach($item as $value)
                    {{ $value['print'] }}<br>
                    @if(isset($value['table']))
                        {!! $value['table'] !!}
                    @endif
                @endforeach
            @endforeach
            @if(isset($auxiliary['model']->remark)&&!is_null($auxiliary['model']->remark)&&''!=$auxiliary['model']->remark)
                <span>备注信息：{{ $auxiliary['model']->remark }}</span>
            @endif
        </div>
    </div>
@endif
{{--并发症--}}
@if (($complication['is_print']))
<div>

    <p class="caseTitle">并发症</p>

    <div>
        @if(!empty($complication['clinical_symptoms']))
            {!! $complication['clinical_symptoms'] !!}
            <br>
        @endif
        @if(!empty($complication['specialty']))
            {!! $complication['specialty'] !!}
            <br>
        @endif
        @if(!empty($complication['prompt']))
            {!! $complication['prompt'] !!}
            <br>
        @endif
        @if(!empty($complication['auxiliary']))
            {!! $complication['auxiliary'] !!}
            <br>
        @endif

        @if(!empty($complication['ordinary']))
            {!! $complication['ordinary'] !!}
            <br>
        @endif
        @if(!empty($complication['fundus']))
            {!! $complication['fundus'] !!}
            <br>
        @endif
        @if(!empty($complication['retinopathy']))
            {!! $complication['retinopathy'] !!}
            <br>
        @endif
        @if(!empty($complication['macular_edema']))
            {!! $complication['macular_edema'] !!}
            <br>
        @endif

    </div>
</div>
@endif
{{--诊断--}}
@if (isset($diagnose) && !is_null($diagnose)&&!isEmpty($diagnose))
    <div class="col-xs-offset-7 col-xs-5">
        @foreach($diagnose['print'] as $item)
            <p>{!! $item !!}</p>
        @endforeach
    </div>
    <div>
        @if(isset($diagnose['model']->remark)&&!is_null($diagnose['model']->remark)&&''!=$diagnose['model']->remark)
            <p>诊断备注：{{ $diagnose['model']->remark }}</p>
        @endif
    </div>
@endif

{{--处理--}}
@if (isset($dispose) && !is_null($dispose))
    <div>
        <p class="caseTitle">Rx:</p>
        <p>{!! $dispose['advise'] !!}</p>
        <div>
            @foreach($dispose['print'] as $item)
                <p>{{ $item }}</p>
            @endforeach
        </div>
        @if($scene->isWestern())
            @if(is_array($dispose['model']['medication']))
                @foreach($dispose['model']['medication'] as $item)
                    <p>
                        {{ fr($item, 'start_time',"：") }}
                        {{ fr($item, 'name','，') }}
                        {{ fr($item, 'usage','，') }}
                        {{--{{ fr($item,'dosage.type','，')}}--}}
                        @if ('每次剂量' == fr($item,'dosage.type'))
                            {{ $item['dosage']['value'],'，'}}
                        @else
                            {{ fe($item, 'dosage.values.morning', '早', '，') }}
                            {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                            {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                            {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                        @endif
                        {{ fr($item, 'dosage.unit','  ,') }}
                        {{--{{ fr($item, 'usage','，') }}--}}
                        {{ fr($item, 'frequency',' ') }}
                        ;
                        {{ fr($item, 'remark',' ') }}
                    </p>
                @endforeach

            @endif
            @if($dispose['model']->cn_medication)

                @foreach((array)$dispose['model']->cn_medication as $item)
                    @if(!isset($item['type']) || $item['type'] == 1)
                        <p>
                            @foreach($item['drugs'] as $drug)
                                {{ $drug['name'] }} {{ $drug['weight'] }}g
                            @endforeach
                            {{ fe($item, 'usage', '煎法：', '，') }}
                            {{ fe($item, 'dosage', '频次：', '，') }}
                            {{ fe($item, 'frequency', '', '，') }}
                            {{ fe($item, 'dose', '总数：', '付') }}
                        </p>
                    @elseif($item['type'] == 3)
                        <p>
                            {{ fe($item, 'name') }}
                            {{ fe($item, 'start_time', '开始于', '，') }}
                            {{ fe($item, 'end_time', '结束于', '，') }}
                            {{ fe($item, 'times_per_day', '每日', '次，') }}
                            {{ fe($item, 'quantity_per_times', '每次') }}
                            {{ fe($item, 'quantity_unit', '', '，') }}
                            {{ fe($item, 'total', '共', '盒，') }}
                        </p>
                    @endif
                @endforeach
            @endif
        @else
        {{--中医处理用药strat--}}
            @if(is_array($dispose['model']['medication']))
                @foreach($dispose['model']['medication'] as $item)
                    <p>
                        {{ fr($item, 'start_time',"：") }}
                        {{ fr($item, 'name','，') }}
                        {{ fr($item, 'usage','，') }}
                        {{--{{ fr($item,'dosage.type','，')}}--}}
                        @if ('每次剂量' == fr($item,'dosage.type'))
                            {{ $item['dosage']['value'],'，'}}
                        @else
                            {{ fe($item, 'dosage.values.morning', '早', '，') }}
                            {{ fe($item, 'dosage.values.atnoon', '中', '，') }}
                            {{ fe($item, 'dosage.values.evening', '晚', '，') }}
                            {{ fe($item, 'dosage.values.before_sleep', '睡前', '，') }}
                        @endif
                        {{ fr($item, 'dosage.unit',' , ') }}
                        {{--{{ fr($item, 'usage','，') }}--}}
                        {{ fr($item, 'frequency',' ') }}
                        ;
                        {{ fr($item, 'remark',' ') }}
                    </p>
                @endforeach
            @endif
            @if($dispose['model']->cn_medication)

                @foreach((array)$dispose['model']->cn_medication as $item)
                    @if(!isset($item['type']) || $item['type'] == 1)
                        <p>
                            @foreach($item['drugs'] as $drug)
                                {{ $drug['name'] }} {{ $drug['weight'] }}g
                            @endforeach
                            {{ fe($item, 'usage', '煎法：', '，') }}
                            {{ fe($item, 'dosage', '频次：', '，') }}
                            {{ fe($item, 'frequency', '', '，') }}
                            {{ fe($item, 'dose', '总数：', '付') }}
                        </p>
                    @elseif($item['type'] == 3)
                        <p>
                            {{ fe($item, 'name') }}
                            {{ fe($item, 'start_time', '开始于', '，') }}
                            {{ fe($item, 'end_time', '结束于', '，') }}
                            {{ fe($item, 'times_per_day', '每日', '次，') }}
                            {{ fe($item, 'quantity_per_times', '每次') }}
                            {{ fe($item, 'quantity_unit', '', '，') }}
                            {{ fe($item, 'total', '共', '盒，') }}
                        </p>
                    @endif
                @endforeach
            @endif
        @endif
        {{--中医用药eng--}}
        @if(isset($dispose['model']->remark)&&!is_null($dispose['model']->remark)&&''!=$dispose['model']->remark)
            <p>备注信息：{{ $dispose['model']->remark }}</p>
        @endif
    </div>
@endif

{{--医生签名--}}
<div class="signature">
    <p class="text-right">医生签名：</p>
</div>